package com.fr.plugin.oauth2;

import java.util.concurrent.ConcurrentHashMap;

public class MyMap {
    private static final ConcurrentHashMap<String, OauthLoginInfo> saves = new ConcurrentHashMap();
    private static final ConcurrentHashMap<String, Long> timers = new ConcurrentHashMap();
    private static final MyMap myMap = new MyMap();
    public static MyMap getObj() {
        return myMap;
    }

    public OauthLoginInfo get(String key) {
        if (!saves.contains(key)){
            return null;
        }
        Long i = timers.get(key);
        if (i == null){
            saves.remove(key);
            timers.remove(key);
            return null;
        }
        if (i < System.currentTimeMillis()){
            saves.remove(key);
            timers.remove(key);
            return null;
        }
        return saves.get(key);
    }

    public void put(String key, OauthLoginInfo value, int time) {
        timers.put(key, System.currentTimeMillis() + time);
        saves.put(key, value);
    }

    public void delete(String key) {
        if (saves.contains(key)){
            saves.remove(key);
        }
        if (timers.contains(key)){
            timers.remove(key);
        }
    }
}
